package cn.sccl.mybatis.junit;

import java.util.Date;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.sccl.mybatis.dao.UserDao;
import cn.sccl.mybatis.pojo.User;

/**
 * @author 饶爽
 * @time 2019年10月8日 下午10:58:38
 * @version 1.0.0
 * 原始的dao开发测试
*/
public class UserDaoTest {
    
    private ApplicationContext context;
    @Before
    public void setUp() throws Exception {
        context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    }
    
    @Test
    public void testQueryUserById() {
        UserDao userDao = context.getBean(UserDao.class);
        User user = userDao.queryUserById(1);
        System.out.println(user);
    }
    
    @Test
    public void testQueryUserByUsername() {
        UserDao userDao = context.getBean(UserDao.class);
        List<User> list = userDao.queryUserByUsername("张");
        for (User user : list) {
            System.out.println(user);
        }
    }

    @Test
    public void testSaveUser() {
        UserDao userDao = context.getBean(UserDao.class);

        User user = new User();
        user.setUsername("曹操");
        user.setSex("1");
        user.setBirthday(new Date());
        user.setAddress("三国");
        userDao.saveUser(user);
        System.out.println(user);
    }

}
